$(function () {
    
    var json;

    $.post("news/user",{},function (data) {
        if (data==null){
            location.href="http://localhost:7777";
        }else {
            if (data.type==1){

            }else if (data.type==0){
                $(".zx").hide()
            }
        };

    });
    //输出用户信息++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function Member_User() {
        $(".m_right").empty();
        $(".m_right").append($('<div class="m_des">\n' +
            '            \t<table border="0" style="width:870px; line-height:22px;" cellspacing="0" cellpadding="0">\n' +
            '                  <tr valign="top">\n' +
            '                    <td width="115"><img src="images/user.jpg" width="90" height="90" /></td>\n' +
            '                    <td>\n' +
            '                    \t<div class="m_user">TRACY</div>\n' +
            '                        <p>\n' +
            '                            等级：<span class="sf">注册用户 </span><br />\n' +
            '                            <!--<font color="#ff4e00">您还差 270 积分达到 分红100</font><br />\n' +
            '                            上一次登录时间: 2015-09-28 18:19:47<br />\n' +
            '                            您还没有通过邮件认证 <a href="#" style="color:#ff4e00;">点此发送认证邮件</a>-->\n' +
            '                        </p>\n' +
            '                        <div class="m_notice">\n' +
            '                        \t用户中心公告！\n' +
            '                        </div>\n' +
            '                    </td>\n' +
            '                  </tr>\n' +
            '                </table>\t\n' +
            '               <button style="background-color: green;margin-left: 50px;margin-top: 20px" class="xiugaixinxi">修改用户信息</button>'+
            '            </div>\n' +
            '\n' +
            '\n' +
            '            <div class="mem_t">账号信息</div>\n' +
            '            <table border="0" class="mon_tab" style="width:870px; margin-bottom:20px;" cellspacing="0" cellpadding="0">\n' +
            '              <tr>\n' +
            '                <td width="40%">登录名：<span style="color:#555555;" class="loginname">12345678</span></td>\n' +
            '                <td width="60%">用户名：<span style="color:#555555;" class="username">邀请人姓名</span></td>\n' +
            '              </tr>\n' +
            '              <tr>\n' +
            '                <td>电&nbsp; &nbsp; 话：<span style="color:#555555;" class="tel">1861111111</span></td>\n' +
            '                <td>邮&nbsp; &nbsp; 箱：<span style="color:#555555;" class="email">12345678@qq.com</span></td>\n' +
            '              </tr>\n' +
            '              <tr>\n' +
            '                <td>身份证号：<span style="color:#555555;" class="sfz">522555123456789</span></td>\n' +
            '                <td>性&nbsp; &nbsp; 别：<span style="color:#555555;" class="sex">男</span></td>\n' +
            '              </tr>\n' +
            '            </table><div class="showxiugai" style="margin-top: 50px"></div>'));


        $.post("news/usershowI",function (data) {
            json = data;
            var sf = "普通用户";
            var sex = "男";
            if(data.sex==0){
                sf = "女";
            }
            if(data.type==1){
                sf = "管理员"
            }
            $(".m_user").html(data.username);
            $(".sf").html(sf);
            $(".loginname").html(data.loginname);
            $(".username").html(data.username);
            $(".tel").html(data.mobile);
            $(".email").html(data.email);
            $(".sfz").html(data.identitycode);
            $(".sex").html(sex);
        })

        //修改信息+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        $(".xiugaixinxi").click(function () {
            $(".showxiugai").empty();
            $(".showxiugai").append($('<table border="0" style="width:420px; font-size:14px; margin-top:20px;" cellspacing="0" cellpadding="0">\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;登录名 &nbsp;</td>\n' +
                '                            <td><input type="text" class="l_mem" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error1"></div></td>\n' +
                '                        </tr>\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;用户名 &nbsp;</td>\n' +
                '                            <td><input type="text" value="" class="l_user" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error2"></div></td>\n' +
                '                        </tr>\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;密码 &nbsp;</td>\n' +
                '                            <td><input type="password" value="" class="l_pwd" id="pw1" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error3"></div></td>\n' +
                '                        </tr>\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;邮箱 &nbsp;</td>\n' +
                '                            <td><input type="text" value="" class="l_email" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error5"></div></td>\n' +
                '                        </tr>\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;手机 &nbsp;</td>\n' +
                '                            <td><input type="text" value="" class="l_tel" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error6"></div></td>\n' +
                '                        </tr>\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right">身份证号 &nbsp;</td>\n' +
                '                            <td><input type="text" value="" class="l_num" /></td>\n' +
                '                        </tr>\n' +
                '                        <tr>\n' +
                '                            <td></td>\n' +
                '                            <td><div style="color: red" class="error7"></div></td>\n' +
                '                        </tr>\n' +
                '\n' +
                '                        <tr height="50">\n' +
                '                            <td align="right">性别 &nbsp;</td>\n' +
                '                            <td>\n' +
                '                                <select style="margin-left: 30px" class="sex">\n' +
                '                                    <option value="0" selected>女</option>\n' +
                '                                    <option value="1">男</option>\n' +
                '                                </select>\n' +
                '                            </td>\n' +
                '                        </tr>\n' +
                '\n' +
                '                        <tr height="60">\n' +
                '                            <td>&nbsp;</td>\n' +
                '                            <td><input type="button" value="修改信息" class="log_btn" /></td>\n' +
                '                        </tr>\n' +
                '                    </table>'))

            //回显修改信息+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            var name;
            var type;

            function chaxun(id) {
                $.post("news/selectById",{"id":id},function (data) {
                    $(".l_mem").val(data.loginname);
                    $(".l_user").val(data.username);
                    //$(".l_pwd").val(data.password);
                    $(".l_email").val(data.email);
                    $(".l_tel").val(data.mobile);
                    $(".l_num").val(data.identitycode);

                    $(".sex").val(data.sex);

                    name = data.loginname;
                    type=data.type;
                })
            }

            chaxun(json.id);


            //验证+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            var flag1 = true;
            var flag2 = true;
            var flag3 = true;
            var flag4 = true;
            var flag5 = true;
            var flag6 = true;
            var flag7 = true;



            $(".l_mem").blur(function () {
                var loginName = $(".l_mem").val();
                $.post("news/selectByName",{"loginName":loginName},function (date) {
                    if(loginName==name){
                        $(".error1").html("登录名可以使用");
                        flag1 = true;
                    }else if(date=="true" && loginName!=""){
                        $(".error1").html("登录名可以使用");
                        flag1 = true;
                    }else if(date=="false"){
                        $(".error1").html("登录名重复");
                        flag1 = false;
                    }else if(loginName==""){
                        $(".error1").html("登录名不能为空");
                        flag1 = false;
                    }
                })
            })

            $(".l_user").blur(function () {
                var aaaa = $(".l_user").val();
                if(aaaa==""){
                    $(".error2").html("用户名不能为空");
                    flag6 = false;
                }else {
                    $(".error2").html("");
                    flag6 = true;
                }
            })

            $("#pw1").blur(function () {
                var zz = /^[a-z0-9]{6,16}$/;
                var password = $("#pw1").val();
                if(!zz.test(password) && password!=""){
                    $(".error3").html("密码必须为6-16位数字或字母");
                    flag2 = false;
                }else if(password==""){
                    $(".error3").html("密码不更改");
                    flag2 = true;
                }else {
                    $(".error3").html("");
                    flag2 = true;
                }
            })

            $(".l_num").blur(function () {
                var zz = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                var sfz = $(".l_num").val();
                if(!zz.test(sfz) && sfz!=""){
                    $(".error7").html("身份证必须是18位");
                    flag3 = false;
                }else {
                    $(".error7").html("");
                    flag3 = true;
                }
            });

            $(".l_email").blur(function () {
                var zz = /^\w+@\w+(\.\w+)+$/;
                var email = $(".l_email").val();
                if(!zz.test(email) && email!=""){
                    $(".error5").html("邮箱格式不正确");
                    flag4 = false;
                }else if(email==""){
                    $(".error5").html("邮箱不能为空");
                    flag4 = false;
                }else {
                    $(".error5").html("");
                    flag4 = true;
                }
            });

            $(".l_tel").blur(function () {
                var zz = /^1[3578]\d{9}$/;
                var tel = $(".l_tel").val();
                if(!zz.test(tel) && tel!=""){
                    $(".error6").html("电话号码必须是11位，且13,15,17,18开头");
                    flag5 = false;
                }else if(tel==""){
                    $(".error6").html("电话号码不能为空");
                    flag5 = false;
                }else {
                    $(".error6").html("");
                    flag5 = true;
                }
            });



            $(".log_btn").click(function () {
                var loginName = $(".l_mem").val();
                var username = $(".l_user").val();
                var password = $("#pw1").val();
                var repassword = $("#pw2").val();
                var email = $(".l_email").val();
                var mobile = $(".l_tel").val();
                var identitycode = $(".l_num").val();
                var sex = $(".sex").val();
                //var type = $(".tp").val();


                if(flag1==false || flag2==false || flag3==false || flag4==false || flag5==false){

                }else if(loginName==""){
                    $(".error1").html("登录名不能为空");
                    $(".error2").html("");
                    $(".error3").html("");
                    $(".error4").html("");
                    $(".error5").html("");
                    $(".error6").html("");
                    $(".error7").html("");
                }else if(username==""){
                    $(".error1").html("");
                    $(".error2").html("用户名不能为空");
                    $(".error3").html("");
                    $(".error4").html("");
                    $(".error5").html("");
                    $(".error6").html("");
                    $(".error7").html("");
                }else if(email==""){
                    $(".error1").html("");
                    $(".error2").html("");
                    $(".error3").html("");
                    $(".error4").html("");
                    $(".error5").html("email不能为空");
                    $(".error6").html("");
                    $(".error7").html("");
                }else if(mobile==""){
                    $(".error1").html("");
                    $(".error2").html("");
                    $(".error3").html("");
                    $(".error4").html("");
                    $(".error5").html("");
                    $(".error6").html("手机号不能为空");
                    $(".error7").html("");
                }else {
                    $.post("news/updateById",{
                        "id":json.id,
                        "loginName":loginName,
                        "username":username,
                        "password":password,
                        "email":email,
                        "mobile":mobile,
                        "identitycode":identitycode,
                        "sex":sex,
                        "type":type
                    },function (date) {
                        if(date=="true"){
                            alert("修改成功");
                            userList(num);
                        }else if(date=="false"){
                            alert("修改失败");
                            userList(num);
                        }
                    })
                }
            })
        })
        
    }

    Member_User();

    //点击用户信息++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".yhxx").click(function () {
        Member_User();
    })


    //咨询列表+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function zixunList(pagenum) {
        $(".m_right").empty();
        $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px;margin-bottom: 10px">咨询列表</h1>\n' +
                '\t\t\t<div class="address">\n' +
                '            \t<table border="1" class="add_t"  style="width:98%; margin:10px auto; text-align: center;font-size: 16px" cellspacing="0" cellpadding="0">\n' +
                '                </table>\n' +
                '            </div>\n' +

            '            <div id="yeshu" class="pages" style="margin-left: 25%">\n' +
            '                <span style="border-color: #333333;border : 1px solid #000000;border-width: 2px;display:inline-block;width: 40px;height:50px;text-align: center;margin-top: 50px;margin-left: 30px">\n' +
            '                    <a href="" style="font-size: 25px;margin-top: 10px;display: inline-block">1</a>\n' +
            '                </span>\n' +
            '            </div>'))
        $.post("news/newsfenye",{"pagenum":pagenum},function (data) {
            $(".add_t").empty();
            $("#yeshu").empty();
            $(".add_t").append($('<tr>\n' +
                '                    <th>标题</th>\n' +
                '                    <th>创建时间</th>\n' +
                '                 <th>操作</th>\n' +
                '                </tr>'));

            $.each(data.list,function (index,news) {
                //var c = escape(news.content);
                //var t = escape(news.title);

                var reg = RegExp(/特惠/);

                if(reg.test(news.title)){
                    $(".add_t").append($('<tr>\n' +
                        '                        <td><a href="javascript:void(0)" class="title" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'"><span style="color: deepskyblue">[ 特惠 ]</span>\n' +
                        '                            <span>' + news.title + '</span></a>\n' +
                        '                        </td>\n' +
                        '                        <td>'+news.createtime+'</td>\n' +
                        '                     <td>&nbsp;&nbsp;<a href="javascript:;" style="" class="xiugai" data-id="'+news.id+'" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;' +
                        '                   <a href="javascript:;" class="shanchu" data-id="'+news.id+'" data-num="'+pagenum+'">删除</a></td>\n' +
                        '                    </tr>'))
                }else {
                    $(".add_t").append($('<tr>\n' +
                        '                        <td><a href="javascript:void(0)" class="title" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'"><span style="color: deepskyblue">[ 公告 ]</span>\n' +
                        '                            <span>' + news.title + '</span></a>\n' +
                        '                        </td>\n' +
                        '                        <td>'+news.createtime+'</td>\n' +
                        '                     <td>&nbsp;&nbsp;<a href="javascript:;" class="xiugai" data-id="'+news.id+'" data-title="'+news.title+'" data-content="'+news.content+'" data-num="'+data.pageNum+'">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;' +
                        '                   <a href="javascript:;" class="shanchu" data-id="'+news.id+'" data-num="'+pagenum+'">删除</a></td>\n' +
                        '                    </tr>'))
                }
            })


            if(data.hasPreviousPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="1">首页</a>\n' +
                    '                </span>')
            }
            $.each(data.navigatepageNums,function (i,a) {
                if(a==data.pageNum){
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" style="background-color: pink" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }else {
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }
            });
            if(data.hasNextPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="'+data.pages+'">末页</a>\n' +
                    '                </span>')
            }


            $(".yeshu").click(function () {
                var a = $(this).data("id");
                zixunList(a);
            })


            //点击进入详细咨询页面+++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".title").click(function () {
                var title = $(this).data("title");
                var content = $(this).data("content");
                var pagenum =  $(this).data("num");
                $(".m_right").empty();
                $(".m_right").append($('<div class="neirong"></div>\n' +
                    '            <div style="margin-left: 800px;margin-top: 100px">\n' +
                    '            <a href="javascipt:void(0)" class="fanhui" style="border: black solid 2px;font-size: 20px">返回</a>\n' +
                    '            </div>'))
                $(".neirong").append($('<h1 style="margin-top: 50px;margin-left: 50px;color: pink">'+title+'</h1>' +
                    '<h2 style="margin-top: 50px;margin-left: 100px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+content+'</h2>'));

                $(".fanhui").click(function () {
                    zixunList(pagenum);
                })
            })

            //点击删除+++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".shanchu").click(function () {
                if(confirm("是否确定删除此条咨询")){
                    var id = $(this).data("id");
                    var pagenum =  $(this).data("num");
                    //alert(pagenum);
                    $.post("news/deletezixun",{"id":id},function (data) {
                        if(data=="true"){
                            alert("删除成功");
                            zixunList(pagenum);
                        }else {
                            alert("删除失败");
                            zixunList(pagenum);
                        }
                    })
                }
            })

            //点击修改+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".xiugai").click(function () {
                var id = $(this).data("id");
                var title = $(this).data("title");
                var content = $(this).data("content");
                var pagenum =  $(this).data("num");

                $(".m_right").empty();
                $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px">修改咨询</h1>\n' +
                    '            <div style="font-size: 20px;margin-top: 50px;margin-left: 50px">\n' +
                    '                标题：<input type="text" name="title" class="title1" style="width: 400px;height: 40px;font-size: 20px">\n' +
                    '                <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
                    '                <br/>\n' +
                    '                内容：<textarea rows="5px" cols="60px" name="content1" class="content1" style="font-size: 20px;margin-top: 30px"></textarea>\n' +
                    '                <div style="font-size: 16px;color: red;margin-left: 60px" class="error2"></div>\n' +
                    '            </div>\n' +
                    '            <div style="margin-left: 650px;margin-top: 50px"><input type="button" value="修改咨询" class="xiugai1" style="font-size: 20px;background-color: #91b817"></div>'))

                $(".title1").val(title);
                $(".content1").val(content);

                var flag1 = true;
                $(".title1").blur(function () {
                    var title1 = $(".title1").val();
                    if(title1==""){
                        $(".error1").html("咨询标题不能为空");
                        flag1 = false;
                    }else {
                        $.post("news/newsByTT",{"title":title1},function (data) {
                            if(data=="true" && data!=title){
                                $(".error1").html("咨询标题重复")
                                flag1 = false;
                            }else {
                                $(".error1").html("")
                                flag1 = true;
                            }
                        });
                    }
                });

                $(".content1").blur(function () {
                    var content1 = $(".content1").val();
                    if(content1==""){
                        $(".error2").html("咨询内容不能为空");
                    }else {
                        $(".error2").html("")
                    }
                })

                $(".xiugai1").click(function () {
                    var title1 = $(".title1").val();
                    var content1 = $(".content1").val();
                    if(title1==""){
                        $(".error1").html("咨询标题不能为空")
                        $(".error2").html("")
                    }else if(content1==""){
                        $(".error1").html("")
                        $(".error2").html("咨询内容不能为空")
                    }else {
                        $.post("news/updatezixun",{"id":id,"title":title1,"content":content1},function (data) {
                            if(data=="true"){
                                alert("修改咨询成功")
                                zixunList(pagenum);
                            }else {
                                alert("修改咨询失败")
                                zixunList(pagenum);
                            }
                        })
                    }
                })
            })

        })
    }

    //点击咨询列表++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".zxlb").click(function () {
        zixunList(1);
    })


    //用户列表++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function userList(pagenum) {
        $(".m_right").empty();
        $(".m_right").append($($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px;margin-bottom: 10px">用户列表</h1>\n' +
            '\t\t\t<div class="address">\n' +
            '            \t<table border="1" class="add_t"  style="width:98%; margin:10px auto; text-align: center;font-size: 16px" cellspacing="0" cellpadding="0">\n' +
            '                </table>\n' +
            '            </div>\n' +

            '            <div id="yeshu" class="pages" style="margin-left: 25%">\n' +
            '                <span style="border-color: #333333;border : 1px solid #000000;border-width: 2px;display:inline-block;width: 40px;height:50px;text-align: center;margin-top: 50px;margin-left: 30px">\n' +
            '                    <a href="" style="font-size: 25px;margin-top: 10px;display: inline-block">1</a>\n' +
            '                </span>\n' +
            '            </div>')))

        $.post("news/userfenye",{"pagenum":pagenum},function (data) {
            $(".add_t").empty();
            $("#yeshu").empty();
            //alert(22222)
            $(".add_t").append($('<tr style="font-size: 20px">\n' +
                '                    <th>用户名称</th>\n' +
                '                    <th>真实姓名</th>\n' +
                '                    <th>性别</th>\n' +
                '                    <th>类型</th>\n' +
                '                    <th>操作</th>\n' +
                '                </tr>'));

            $.each(data.list,function (index,user) {
                var sex = '男';
                var type = '管理员';
                if(user.sex==0){
                    sex = '女'
                }
                if(user.type==0){
                    type = '普通用户';
                    $(".add_t").append($('<tr>\n' +
                        '                        <th>'+user.loginname+'</th>\n' +
                        '                        <th>'+user.username+'</th>\n' +
                        '                        <th>'+sex+'</th>\n' +
                        '                        <th>'+type+'</th>\n' +
                        '                        <th><a href="javascript:void(0)" data-id="'+user.id+'" data-num="'+data.pageNum+'" class="xiugai">修改</a><a href="javascript:void(0)" style="margin-left: 20px" class="shanchu" data-id="'+user.id+'" data-num="'+data.pageNum+'">删除</a></th>\n' +
                        '                    </tr>'))
                }else {
                    $(".add_t").append($('<tr>\n' +
                        '                        <th>'+user.loginname+'</th>\n' +
                        '                        <th>'+user.username+'</th>\n' +
                        '                        <th>'+sex+'</th>\n' +
                        '                        <th>'+type+'</th>\n' +
                        '                        <th><a href="javascript:void(0)" data-id="'+user.id+'" data-num="'+data.pageNum+'"  class="xiugai">修改</a><a href="javascript:void(0)" style="margin-left: 20px" class="shanchu" data-id="'+user.id+'" data-num="'+data.pageNum+'"></a></th>\n' +
                        '                    </tr>'))
                }
            })


            if(data.hasPreviousPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="1">首页</a>\n' +
                    '                </span>')
            }
            $.each(data.navigatepageNums,function (i,a) {
                if(a==data.pageNum){
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" style="background-color: pink" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }else {
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }
            });
            if(data.hasNextPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="'+data.pages+'">末页</a>\n' +
                    '                </span>')
            }



            $(".yeshu").click(function () {
                var a = $(this).data("id");
                userList(a);
            })

            //点击删除用户+++++++++++++++++++++++++++++++++++++++++++++++++
            $(".shanchu").on("click",function () {
                if(confirm("是否删除该用户")){
                    var id = $(this).data("id");
                    var pagenum = $(this).data("num");
                    $.post("news/deleteById",{"id":id},function (data) {
                        if(data=="true"){
                            alert("删除用户成功");
                            userList(pagenum);
                        }else{
                            alert("删除用户失败");
                            userList(pagenum);
                        }
                    })
                }
            })

            //点击修改用户++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".xiugai").click(function () {
                var num = $(this).data("num");
                var id = $(this).data("id");
                $(".m_right").empty();
                $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px">修改用户</h1>\n' +
                    '            <div class="updatelist" style="margin-top: 100px">\n' +
                    '                <form>\n' +
                    '                    <table border="0" style="width:420px; font-size:14px; margin-top:20px;" cellspacing="0" cellpadding="0">\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;登录名 &nbsp;</td>\n' +
                    '                            <td><input type="text" class="l_mem" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error1"></div></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;用户名 &nbsp;</td>\n' +
                    '                            <td><input type="text" value="" class="l_user" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error2"></div></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;密码 &nbsp;</td>\n' +
                    '                            <td><input type="password" value="" class="l_pwd" id="pw1" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error3"></div></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;邮箱 &nbsp;</td>\n' +
                    '                            <td><input type="text" value="" class="l_email" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error5"></div></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right"><font color="#ff4e00">*</font>&nbsp;手机 &nbsp;</td>\n' +
                    '                            <td><input type="text" value="" class="l_tel" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error6"></div></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right">身份证号 &nbsp;</td>\n' +
                    '                            <td><input type="text" value="" class="l_num" /></td>\n' +
                    '                        </tr>\n' +
                    '                        <tr>\n' +
                    '                            <td></td>\n' +
                    '                            <td><div style="color: red" class="error7"></div></td>\n' +
                    '                        </tr>\n' +
                    '\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right">性别 &nbsp;</td>\n' +
                    '                            <td>\n' +
                    '                                <select style="margin-left: 30px" class="sex">\n' +
                    '                                    <option value="0" selected>女</option>\n' +
                    '                                    <option value="1">男</option>\n' +
                    '                                </select>\n' +
                    '                            </td>\n' +
                    '                        </tr>\n' +
                    '\n' +
                    '                        <tr height="50">\n' +
                    '                            <td align="right">用户类型 &nbsp;</td>\n' +
                    '                            <td>\n' +
                    '                                <select style="margin-left: 30px" class="tp">\n' +
                    '                                    <option value="0" selected>普通用户</option>\n' +
                    '                                    <option value="1">管理员</option>\n' +
                    '                                </select>\n' +
                    '                            </td>\n' +
                    '                        </tr>\n' +
                    '\n' +
                    '                        <tr height="60">\n' +
                    '                            <td>&nbsp;</td>\n' +
                    '                            <td><input type="button" value="修改信息" class="log_btn" /></td>\n' +
                    '                        </tr>\n' +
                    '\n' +
                    '\n' +
                    '                    </table>\n' +
                    '                    <div style="margin-left: 800px;margin-top: -40px">\n' +
                    '                        <a href="javascript:void(0)" class="fanhui" style="border: black solid 2px;font-size: 20px">返回</a>\n' +
                    '                    </div>\n' +
                    '                </form>\n' +
                    '            </div>'))

                var name;

                function chaxun(id) {
                    $.post("news/selectById",{"id":id},function (data) {
                        $(".l_mem").val(data.loginname);
                        $(".l_user").val(data.username);
                        //$(".l_pwd").val(data.password);
                        $(".l_email").val(data.email);
                        $(".l_tel").val(data.mobile);
                        $(".l_num").val(data.identitycode);

                        $(".sex").val(data.sex);
                        $(".tp").val(data.type);

                        name = data.loginname;
                    })
                }

                chaxun(id);


            //验证+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                var flag1 = true;
                var flag2 = true;
                var flag3 = true;
                var flag4 = true;
                var flag5 = true;
                var flag6 = true;
                var flag7 = true;



                $(".l_mem").blur(function () {
                    var loginName = $(".l_mem").val();
                    $.post("news/selectByName",{"loginName":loginName},function (date) {
                        if(loginName==name){
                            $(".error1").html("登录名可以使用");
                            flag1 = true;
                        }else if(date=="true" && loginName!=""){
                            $(".error1").html("登录名可以使用");
                            flag1 = true;
                        }else if(date=="false"){
                            $(".error1").html("登录名重复");
                            flag1 = false;
                        }else if(loginName==""){
                            $(".error1").html("登录名不能为空");
                            flag1 = false;
                        }
                    })
                })

                $(".l_user").blur(function () {
                    var aaaa = $(".l_user").val();
                    if(aaaa==""){
                        $(".error2").html("用户名不能为空");
                        flag6 = false;
                    }else {
                        $(".error2").html("");
                        flag6 = true;
                    }
                })

                $("#pw1").blur(function () {
                    var zz = /^[a-z0-9]{6,16}$/;
                    var password = $("#pw1").val();
                    if(!zz.test(password) && password!=""){
                        $(".error3").html("密码必须为6-16位数字或字母");
                        flag2 = false;
                    }else if(password==""){
                        $(".error3").html("密码不更改");
                        flag2 = true;
                    }else {
                        $(".error3").html("");
                        flag2 = true;
                    }
                })

                $(".l_num").blur(function () {
                    var zz = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    var sfz = $(".l_num").val();
                    if(!zz.test(sfz) && sfz!=""){
                        $(".error7").html("身份证必须是18位");
                        flag3 = false;
                    }else {
                        $(".error7").html("");
                        flag3 = true;
                    }
                });

                $(".l_email").blur(function () {
                    var zz = /^\w+@\w+(\.\w+)+$/;
                    var email = $(".l_email").val();
                    if(!zz.test(email) && email!=""){
                        $(".error5").html("邮箱格式不正确");
                        flag4 = false;
                    }else if(email==""){
                        $(".error5").html("邮箱不能为空");
                        flag4 = false;
                    }else {
                        $(".error5").html("");
                        flag4 = true;
                    }
                });

                $(".l_tel").blur(function () {
                    var zz = /^1[3578]\d{9}$/;
                    var tel = $(".l_tel").val();
                    if(!zz.test(tel) && tel!=""){
                        $(".error6").html("电话号码必须是11位，且13,15,17,18开头");
                        flag5 = false;
                    }else if(tel==""){
                        $(".error6").html("电话号码不能为空");
                        flag5 = false;
                    }else {
                        $(".error6").html("");
                        flag5 = true;
                    }
                });



                $(".log_btn").click(function () {
                    var loginName = $(".l_mem").val();
                    var username = $(".l_user").val();
                    var password = $("#pw1").val();
                    var repassword = $("#pw2").val();
                    var email = $(".l_email").val();
                    var mobile = $(".l_tel").val();
                    var identitycode = $(".l_num").val();
                    var sex = $(".sex").val();
                    var type = $(".tp").val();


                    if(flag1==false || flag2==false || flag3==false || flag4==false || flag5==false){

                    }else if(loginName==""){
                        $(".error1").html("登录名不能为空");
                        $(".error2").html("");
                        $(".error3").html("");
                        $(".error4").html("");
                        $(".error5").html("");
                        $(".error6").html("");
                        $(".error7").html("");
                    }else if(username==""){
                        $(".error1").html("");
                        $(".error2").html("用户名不能为空");
                        $(".error3").html("");
                        $(".error4").html("");
                        $(".error5").html("");
                        $(".error6").html("");
                        $(".error7").html("");
                    }else if(email==""){
                        $(".error1").html("");
                        $(".error2").html("");
                        $(".error3").html("");
                        $(".error4").html("");
                        $(".error5").html("email不能为空");
                        $(".error6").html("");
                        $(".error7").html("");
                    }else if(mobile==""){
                        $(".error1").html("");
                        $(".error2").html("");
                        $(".error3").html("");
                        $(".error4").html("");
                        $(".error5").html("");
                        $(".error6").html("手机号不能为空");
                        $(".error7").html("");
                    }else {
                        $.post("news/updateById",{
                            "id":id,
                            "loginName":loginName,
                            "username":username,
                            "password":password,
                            "email":email,
                            "mobile":mobile,
                            "identitycode":identitycode,
                            "sex":sex,
                            "type":type
                        },function (date) {
                            if(date=="true"){
                                alert("修改成功");
                                userList(num);
                            }else if(date=="false"){
                                alert("修改失败");
                                userList(num);
                            }
                        })
                    }
                })

                $(".m_right a").click(function () {
                    userList(num);
                })
            })

        })
    }

    //点击用户列表++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".yhlb").click(function () {
        userList(1);
    })
    
    //我的订单
    function myOrder(userid,p) {
        $(".m_right").empty();
        $.post("news/xianshiDD", {"userid": userid}, function (data) {
            var pages = (data.length % 2 == 0) ? data.length / 2 : data.length / 2 + 1;
            var ps = parseInt(pages)
            console.log(pages)
            console.log(data)
            var l = (p - 1) * 2;
            $(".m_right").append(     '           <div class="mem_tit">我的订单</div>\n' )
            $.each(data, function (i, order) {
                console.log(order   )
                var lala=(order.refund==0)?"未申请退货":"已退款退货";

                if (i >= l && i < (l + 2)) {
                    $(".m_right").append(
                        '            <table border="0" class="dingdan order_tab' + i + '" style="width:930px; text-align:center; margin-bottom:30px;" cellspacing="0" cellpadding="0">\n' +
                        '              <tr bgcolor="#ffc0cb">                                                                                                                                                    \n' +
                        '                <td width="45%">订单号：' + order.serialnumber + '</td>\n' +
                        '                <td width="35%">下单时间：' + order.createtime + '</td>\n' +
                        '                <td width="25%">订单总金额：' + order.cost + '</td>\n' +
                        '              </tr>\n' +
                        '              <tr bgcolor="#ffc0cb">                                                                                                                                                    \n' +
                        '                <td width="15%">用户地址:' + order.useraddress + '</td>\n' +
                        '                <td width="10%">是否退货退款:' +lala+ '</td>\n' +
                        '                <td width="10%"><button class="tuikuan" data-id="'+order.id+'" data-refund="'+order.refund+'">申请退货退款</button></td>\n' +
                        '              </tr>\n' +
                        "<tr>\n" +
                        "        <td >商品名称</td>\n" +
                        "        <td >购买数量</td>\n" +
                        "        <td >小计</td>\n" +
                        "    </tr>\n" +
                        '            </table>')
                    $.each(data[i].list, function (index, o) {
                        if ((o.orderid) == (order.id)) {
                            $(".order_tab" + i).append(
                                "<tr>\n" +
                                "        <td ><img src='../../files/" + o.list.filename + "' width='40px' height='40px'>" + o.list.name + "</td>\n" +
                                "        <td >" + o.quantity + "</td>\n" +
                                "        <td >" + o.cost + "</td>\n" +
                                "<td></td>" +
                                "    </tr>\n"
                            )
                        }
                    })
                }
            })


            $(".m_right").append(
                "<a class='ddfy' data-p='1'  href='javascript:;'>首页</a>"
            )
            if (p > 1) {
                $(".m_right").append(
                    "<a class='ddfy' data-p='" + (p - 1) + "'  href='javascript:;'>上一页</a>"
                )
            }
            if (p < ps) {
                $(".m_right").append(
                    "<a class='ddfy' data-p='" + (p + 1) + "' href='javascript:;'>下一页</a>"
                )
            }
            $(".m_right").append(
                "<a class='ddfy' data-p='" + ps + "' href='javascript:;'>末页</a>"
            )
            // $.post("news/myOrder", {"userid": userid}, function (data) {
            //     $(".m_right").append($('<p></p>' +
            //         '           <div class="mem_tit">我的订单</div>\n' +
            //         '            <table border="0" class="order_tab" style="width:930px; text-align:center; margin-bottom:30px;" cellspacing="0" cellpadding="0">\n' +
            //         '              <tr>                                                                                                                                                    \n' +
            //         '                <td width="20%">订单号</td>\n' +
            //         '                <td width="25%">下单时间</td>\n' +
            //         '                <td width="15%">订单总金额</td>\n' +
            //         '                <td width="25%">用户地址</td>\n' +
            //         '              </tr>\n' +
            //         '            </table>'));
            //     if (data == "false") {
            //         $(".order_tab").append($('<tr>' +
            //             '<th colspan="4">暂无订单</th>' +
            //             '</tr>'))
            //     } else {
            //         $.each(data, function (index, order) {
            //             $(".order_tab").append($('<tr>\n' +
            //                 '                <td><font color="#ff4e00">' + order.serialnumber + '</font></td>\n' +
            //                 '                <td>' + order.createtime + '</td>\n' +
            //                 '                <td>￥' + order.cost + '</td>\n' +
            //                 '                <td>' + order.useraddress + '</td>\n' +
            //                 '              </tr>'))
            //         })
            //     }
            // })


            $(".ddfy").click(function () {
                    myOrder(json.id, $(this).data('p'))
            })
            //退款
            $(".tuikuan").click(function () {
                var id=$(this).data('id');
                var refund=$(this).data('refund');
               if (refund==0){
                   $.post("news/tuikuan",{"id":id},function (data) {
                       if (data=="true"){
                           $.post("news/out",{"id":id},function (data) {
                               alert(data.msg)
                               location.reload()
                           })
                       }else {
                           alert("超过30分钟的订单不能申请退货退款！")
                       }
                   })
               }else {
                   alert("已退货退款,请不要重复操作")
               }
            })

        })
    }

    //点击我的订单+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".wddd").click(function () {
        myOrder(json.id,1);
    })

    function all(p){
        $(".m_right").empty();
        $.post("news/xianshiDD",{"userid":0},function (data) {
            var pages = (data.length % 2 == 0) ? data.length / 2 : data.length / 2 + 1;
            var ps = parseInt(pages)
            console.log(pages)
            console.log(data)
            var l = (p - 1) * 2;
            $(".m_right").append(     '           <div class="mem_tit">全部订单</div>\n' )
            $.each(data, function (i, order) {
                var lala=order.refund==0?"未申请退货":"已退款退货";
                if (i >= l && i < (l + 2)) {
                    $(".m_right").append(
                        '            <table border="0" class="dingdan order_tab' + i + '" style="width:930px; text-align:center; margin-bottom:30px;" cellspacing="0" cellpadding="0">\n' +
                        '              <tr bgcolor="#ffc0cb">                                                                                                                                                    \n' +
                        '                <td width="35%">订单号：' + order.serialnumber + '</td>\n' +
                        '                <td width="30%">下单时间：' + order.createtime + '</td>\n' +
                        '                <td width="15%">订单总金额：' + order.cost + '</td>\n' +
                        '              </tr>\n' +
                        '              <tr bgcolor="#ffc0cb">                                                                                                                                                    \n' +
                        '                <td width="15%">用户地址:' + order.useraddress + '</td>\n' +
                        '                <td width="10%">是否退货退款:' +lala+ '</td>\n' +
                        '                <td width="10%"><button class="tuikuan" data-id="'+order.id+'" data-refund="'+order.refund+'">申请退货退款</button></td>\n' +
                        '              </tr>\n' +
                        "<tr>\n" +
                        "        <td >商品名称</td>\n" +
                        "        <td >购买数量</td>\n" +
                        "        <td >小计</td>\n" +
                        "    </tr>\n" +
                        '            </table>')
                    $.each(data[i].list, function (index, o) {
                        if ((o.orderid) == (order.id)) {
                            $(".order_tab" + i).append(
                                "<tr>\n" +
                                "        <td ><img src='../../files/" + o.list.filename + "' width='40px' height='40px'>" + o.list.name + "</td>\n" +
                                "        <td >" + o.quantity + "</td>\n" +
                                "        <td >" + o.cost + "</td>\n" +
                                "    </tr>\n"
                            )
                        }
                    })
                }
            })


            $(".m_right").append(
                "<a class='ddfy' data-p='1'  href='javascript:;'>首页</a>"
            )
            if (p > 1) {
                $(".m_right").append(
                    "<a class='ddfy' data-p='" + (p - 1) + "'  href='javascript:;'>上一页</a>"
                )
            }
            if (p < ps) {
                $(".m_right").append(
                    "<a class='ddfy' data-p='" + (p + 1) + "' href='javascript:;'>下一页</a>"
                )
            }
            $(".m_right").append(
                "<a class='ddfy' data-p='" + ps + "' href='javascript:;'>末页</a>"
            )


            $(".ddfy").click(function () {
                all( $(this).data('p'))
            })
            //退款
            $(".tuikuan").click(function () {
                var id=$(this).data('id');
                var refund=$(this).data('refund');
                if (refund==0){
                    $.post("news/tuikuan",{"id":id},function (data) {
                        if (data=="true"){
                            $.post("news/out",{"id":id},function (data) {
                                alert(data.msg)
                                location.reload()
                            })
                        }else {
                            alert("超过30分钟的订单不能申请退货退款！")
                        }
                    })
                }else {
                    alert("已退货退款,请不要重复操作")
                }
            })
        })
    }

    //点击全部订单+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".qbdd").click(function () {
        all(1);
    })



    //收货地址+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function myaddress(id) {
        $(".m_right").empty();
        $.post("news/myaddress",{"userid":id},function (data) {
            $(".m_right").append($('\t\t\t<input type="hidden" name="userid" value="" />\n' +
                '            <p></p>\n' +
                '            <div class="mem_tit">收货地址</div>\n' +
                '\t\t\t<div class="address">\n' +
                '            \t<table border="1" class="add_t"  style="width:98%; margin:10px auto; text-align: center;" cellspacing="0" cellpadding="0">\n' +
                '                </table>\n' +
                '            </div>\n' +
                '\n' +
                '            <div class="mem_tit">\n' +
                '            \t<a href="javascript:;" id="conceal"><img src="images/add_ad.gif" /></a>\n' +
                '            </div>\n' +
                '\t\t\t<div id="toogle" style="display: none;">\n' +
                '            <table border="0" class="add_tab" style="width:930px;"  cellspacing="0" cellpadding="0">\n' +
                '              <tr>\n' +
                '                <td align="right">收货地址</td>\n' +
                '                <td style="font-family:\'宋体\';"><input type="text" value="" id="dizhi" class="add_ipt" /><span style="color: red;">（必填）</span></td>\n' +
                '                <td align="right">备注</td>\n' +
                '                <td style="font-family:\'宋体\';"><input type="text" value="" id="beizhu" class="add_ipt" /></td>\n' +
                '              </tr>\n' +
                '            </table>\n' +
                '           \t<p align="right">\n' +
                '            \t<a href="javascript:;" class="add_b">确认添加</a>\n' +
                '            </p> \n' +
                '           </div>   \n'));
            $(".add_t").append($('<tr>' +
                '<td><是否默认</td>' +
                '<td>地址</td>' +
                '<td>创建时间</td>' +
                '<td>备注</td>' +
                '<td>操作</td>' +
                '</tr>'))

            $.each(data,function (index,address) {
                //alert(address.isdefault);
                if(address.isdefault=="1"){
                    $(".add_t").append($('<tr>' +
                        '<td><input type="radio" name="moren" class="moren" value="'+address.id+'" checked/></td>' +
                        '<td>'+address.address+'</td>' +
                        '<td>'+address.createtime+'</td>' +
                        '<td>'+address.remark+'</td>' +
                        '<td><a href="javascript:;" class="shanchu" data-id="'+address.id+'">删除</a></td>' +
                        '</tr>'))
                }else {
                    $(".add_t").append($('<tr>' +
                        '<td><input type="radio" name="moren" class="moren" value="'+address.id+'"/></td>' +
                        '<td>'+address.address+'</td>' +
                        '<td>'+address.createtime+'</td>' +
                        '<td>'+address.remark+'</td>' +
                        '<td><a href="javascript:;" class="shanchu" data-id="'+address.id+'">删除</a></td>' +
                        '</tr>'))
                }
            })

            //点击显示增加地址++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $("#conceal").click(function () {
                $("#toogle").show();
            })

            //增加地址++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".add_b").click(function () {
                var dizhi = $("#dizhi").val();
                var beizhu = $("#beizhu").val();
                if(dizhi==""){
                    alert("地址不能为空");
                }else {
                    $.post("news/insertAddress",{
                        "userid" : json.id,
                        "address" : dizhi,
                        "remark" : beizhu
                    },function (data) {
                        if(data=="true"){
                            alert("添加地址成功");
                            myaddress(json.id);
                        }else {
                            alert("添加地址失败");
                            myaddress(json.id);
                        }
                    })
                }
            })

            //删除地址++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".shanchu").click(function () {
                if(confirm("是否确定删除")){
                    var id = $(this).data("id")
                    $.post("news/deleteAdress",{"id":id},function (data) {
                        if(data=="true"){
                            alert("删除地址成功");
                            myaddress(json.id);
                        }else {
                            alert("删除地址失败");
                            myaddress(json.id);
                        }
                    })
                }
            })

            //选择默认地址
            $(".moren").click(function () {
                var id = $(this).val();
                $.post("news/updatemoren",{"id":id,"userid":json.id},function (data) {})
            })
            
        })

    }

    //点击地址+++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".shdz").click(function () {
        myaddress(json.id);
    })
    
    
    
    //添加咨询+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function addzixun() {
        $(".m_right").empty();
        $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px">添加咨询</h1>\n' +
            '            <div style="font-size: 20px;margin-top: 50px;margin-left: 50px">\n' +
            '                标题：<input type="text" name="title" class="title1" style="width: 400px;height: 40px;font-size: 20px">\n' +
            '                <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
            '                <br/>\n' +
            '                内容：<textarea rows="5px" cols="60px" name="content1" class="content1" style="font-size: 20px;margin-top: 30px"></textarea>\n' +
            '                <div style="font-size: 16px;color: red;margin-left: 60px" class="error2"></div>\n' +
            '            </div>\n' +
            '            <div style="margin-left: 650px;margin-top: 50px"><input type="button" value="添加咨询" class="tianjia1" style="font-size: 20px;background-color: #91b817"></div>'))


        var flag1 = true;
        $(".title1").blur(function () {
            var title1 = $(".title1").val();
            if(title1==""){
                $(".error1").html("咨询标题不能为空");
                flag1 = false;
            }else {
                $.post("news/newsByTT",{"title":title1},function (data) {
                    if(data=="true"){
                        $(".error1").html("咨询标题重复")
                        flag1 = false;
                    }else {
                        $(".error1").html("")
                        flag1 = true;
                    }
                });
            }
        });

        $(".content1").blur(function () {
            var content1 = $(".content1").val();
            if(content1==""){
                $(".error2").html("咨询内容不能为空");
            }else {
                $(".error2").html("")
            }
        })

        $(".tianjia1").click(function () {
            var title1 = $(".title1").val();
            var content1 = $(".content1").val();
            if(title1==""){
                $(".error1").html("咨询标题不能为空")
                $(".error2").html("")
            }else if(content1==""){
                $(".error1").html("")
                $(".error2").html("咨询内容不能为空")
            }else if(!flag1){

            }else {
                $.post("news/addzixun",{"title":title1,"content":content1},function (data) {
                    if(data=="true"){
                        alert("添加咨询成功")
                        zixunList(1);
                    }else {
                        alert("添加咨询失败")
                        addzixun();
                    }
                })
            }
        })

    }

    //点击添加咨询++++++++++++++++++++++++++++++++++++++++++
    $(".tjzx").click(function () {
        addzixun();
    })





    //商品管理++++++++++++++++++++++++++++++++++++++++++++++++++
    function productList(pagenum) {
        $(".m_right").empty();
        $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px;margin-bottom: 10px">商品列表</h1>\n' +
            '\t\t\t<div class="address">\n' +
            '            \t<table border="1" class="add_t"  style="width:98%; margin:10px auto; text-align: center;font-size: 16px" cellspacing="0" cellpadding="0">\n' +
            '                </table>\n' +
            '            </div>\n' +
            '\n' +
            '            <div id="yeshu" class="pages">\n' +
            '                <span style="border-color: #333333;border : 1px solid #000000;border-width: 2px;display:inline-block;width: 40px;height:50px;text-align: center;margin-top: 50px;margin-left: 30px">\n' +
            '                    <a href="" style="font-size: 25px;margin-top: 10px;display: inline-block">1</a>\n' +
            '                </span>\n' +
            '            </div>'))

        $(".add_t").empty();
        $("#yeshu").empty();
        $(".add_t").append($('<tr style="font-size: 16px">\n' +
            '                    <th>商品示例</th>\n' +
            '                    <th>商品名字</th>\n' +
            '                    <th>商品价格</th>\n' +
            '                  <th>库存</th>\n' +
            '                 <th>操作</th>\n' +
            '                </tr>'));

        $.post("news/selectPAll",{"pageNum":pagenum},function (data) {
            $.each(data.list,function (index,produck) {
                    $(".add_t").append($('<tr style="font-size: 16px">\n' +
                        '                    <th><img src="http://39.104.78.30:1234/files/'+produck.filename+'" style="width: 50px;height: 50px"></th>\n' +
                        '                    <th>'+produck.name+'</th>\n' +
                        '                    <th>'+produck.price+'￥</th>\n' +
                        '                  <th>'+produck.stock+'</th>\n' +
                        '                 <th><a href="javascript:;" class="xiugaiSP" data-id="'+produck.id+'" data-num="'+pagenum+'">修改</a> &nbsp; &nbsp;<a href="javascript:;" class="shanchusp" data-id="'+produck.id+'" data-num="'+pagenum+'">删除</a></th>\n' +
                        '                </tr>'));
            })

            if(data.hasPreviousPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="1">首页</a>\n' +
                    '                </span>')
            }
            $.each(data.navigatepageNums,function (i,a) {
                if(a==data.pageNum){
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" style="background-color: pink" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }else {
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }
            });
            if(data.hasNextPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="'+data.pages+'">末页</a>\n' +
                    '                </span>')
            }

            $(".yeshu").click(function () {
                var a = $(this).data("id");
                productList(a);
            })


            //删除商品+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".shanchusp").click(function () {
                if(confirm("是否确定删除此商品")){
                    var id = $(this).data("id");
                    var num = $(this).data("num");
                    $.post("news/deletePbyid",{"id":id},function (data) {
                        if(data=="true"){
                            alert("删除商品成功");
                            productList(num);
                        }else {
                            alert("删除商品失败");
                            productList(num);
                        }
                    })
                }
            })


            //修改商品++++++++++++++++++++++++++++++++++++++++++++++++
            $(".xiugaiSP").click(function () {
                var id = $(this).data("id");
                var num = $(this).data("num");
                $(".m_right").empty();
                $.post("news/selectbyid",{"id":id},function (data) {
                    $(".m_right").empty();
                    $(".m_right").append($('<form id="formXG" action=""><h1 style="font-size: 30px;margin-left: 400px;margin-top: 50px">修改商品</h1>\n' +
                        '            <div style="font-size: 20px;margin-top: 50px;margin-left: 150px"><input type="hidden" name="id" class="id" value="'+data.id+'"/>\n' +
                        '                <div>\n' +
                        '                    名字：<input type="text" name="name" class="name" value="'+data.name+'" style="width: 400px;height: 40px;font-size: 20px">\n' +
                        '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div style="margin-top: 40px">\n' +
                        '                    描述：<input type="text" name="description" value="'+data.description+'" class="description" style="width: 400px;height: 40px;font-size: 20px">\n' +
                        '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error2"></div>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div style="margin-top: 40px">\n' +
                        '                    价格：<input type="text" name="price" value="'+data.price+'" class="price" style="width: 400px;height: 40px;font-size: 20px">\n' +
                        '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error3"></div>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div style="margin-top: 40px">\n' +
                        '                    库存：<input type="text" name="stock" value="'+data.stock+'" class="stock" style="width: 400px;height: 40px;font-size: 20px">\n' +
                        '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error4"></div>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div class="fenlei1" style="margin-top: 40px">\n' +
                        '                    一级分类：<select class="categorylevel1id" name="categorylevel1id">\n'+
                        '              <option value="0" class="cl1">请选择</option>'+
                        '                </select>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div class="fenlei2" style="margin-top: 40px">\n' +
                        '                    二级分类：<select class="categorylevel2id" name="categorylevel2id">\n' +
                        '              <option value="0" class="cl2">请选择</option>'+
                        '                </select>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div class="fenlei3" style="margin-top: 40px">\n' +
                        '                    三级分类：<select class="categorylevel3id" name="categorylevel3id">\n' +
                        '              <option value="0" class="cl3">请选择</option>'+
                        '                </select>\n' +
                        '                </div>\n' +
                        '\n' +
                        '                <div style="margin-top: 40px">\n' +
                        '                    图片：<img src="http://39.104.78.30:1234/files/'+data.filename+'" alt="暂无图片" style="height: 200px;width: 200px"><input type="file" name="file" class="file">\n' +
                        '               <div style="font-size: 16px;color: red;margin-left: 60px" class="error5"></div>\n' +
                        '                </div>\n' +
                        '                \n' +
                        '         </div>\n' +
                        '                <div style="margin-left: 650px;margin-top: 50px"><input type="button" value="修改商品信息" class="xgspxx" style="font-size: 16px;background-color: #91b817"> &nbsp; &nbsp;<input type="button" style="font-size: 16px;background-color: #91b817" class="fanhuiGL" value="返回"></div>' +
                        '</form>'))

                    $.post("news/spfenlei",{"type":1},function (list) {
                        $(".categorylevel1id").empty();
                        $(".categorylevel2id").empty();
                        $(".categorylevel3id").empty();

                        $(".categorylevel1id").append($('<option value="0" class="cl1">请选择</option>'))
                        $.each(list[0],function (index,order) {
                            if(order.id==data.categorylevel1id){
                                $(".categorylevel1id").append($('<option value="'+order.id+'" class="cl1" selected>'+order.name+'</option>'))
                            }else{
                                $(".categorylevel1id").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
                            }
                        });

                        $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'))
                        $.each(list[1],function (index,order) {
                            if(data.categorylevel2id==null){

                            }else if(order.id==data.categorylevel2id){
                                $(".categorylevel2id").append($('<option value="'+order.id+'" class="cl2" selected>'+order.name+'</option>'))
                            }else if(order.parentid==data.categorylevel1id){
                                $(".categorylevel2id").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                            }
                        });

                        $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'))
                        $.each(list[2],function (index,order) {
                            if(data.categorylevel3id==null){

                            }else if(order.id==data.categorylevel3id){
                                $(".categorylevel3id").append($('<option value="'+order.id+'" class="cl3" selected>'+order.name+'</option>'))
                            }else if(order.parentid==data.categorylevel2id){
                                $(".categorylevel3id").append($('<option value="'+order.id+'" class="cl3">'+order.name+'</option>'))
                            }
                        });


                        $(".categorylevel1id").change(function () {
                            var a = $(this).val();
                            if(a==0){
                                $(".fenlei2").hide();
                                $(".categorylevel2id").empty();
                                $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'));
                                $(".categorylevel3id").empty();
                                $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                            }else {
                                $(".fenlei2").show();
                                $(".categorylevel3id").empty();
                                $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                            }
                            $(".categorylevel2id").empty();
                            $(".fenlei3").hide();
                            $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'));
                            $.each(list[1],function (index,order) {
                                if(order.parentid==a){
                                    $(".categorylevel2id").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                                }
                            });
                        });

                        $(".categorylevel2id").change(function () {
                            var a = $(this).val();
                            if(a==0){
                                $(".fenlei3").hide();
                                $(".categorylevel3id").empty();
                                $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                            }else {
                                $(".fenlei3").show();
                            }
                            $(".categorylevel3id").empty();
                            //$(".fenlei3").hide();
                            $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                            $.each(list[2],function (index,order) {
                                if(order.parentid==a){
                                    $(".categorylevel3id").append($('<option value="'+order.id+'" class="cl3">'+order.name+'</option>'))
                                }
                            });
                        })


                        var flag = true;
                        var flag1 = true;
                        var flag2 = true;
                        var flag3 = true;
                        $(".name").blur(function () {
                            var name = $(".name").val();
                            if(name==""){
                                $(".error1").html("商品名字不能为空");
                                flag=false;
                            }else if(name==data.name){
                                $(".error1").html("商品名字可以使用");
                                flag = true;
                            }else {
                                $.post("news/produckByName",{"name":name},function (rs) {
                                    if(rs=="false"){
                                        $(".error1").html("商品名字可以使用");
                                        flag = true;
                                    }else if(rs=="true" && name!=data.name){
                                        $(".error1").html("商品名字重复");
                                        flag = false;
                                    }
                                })
                            }
                        })

                        var reg = /^[0-9]*[1-9][0-9]*$/;
                        var reg1 = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/;

                        $(".price").blur(function () {
                            var price = $(".price").val();
                            if(price==""){
                                $(".error3").html("商品价格不能为空");
                                flag1 = false;
                            }if(!reg1.test(price)){
                                $(".error3").html("商品价格只能为数字，包括带小数点的数字");
                                flag1 = false;
                            }else {
                                $(".error3").html("");
                                flag1 = true;
                            }
                        });

                        $(".stock").blur(function () {
                            var stock = $(".stock").val();
                            if(stock==""){
                                $(".error4").html("商品库存不能为空");
                                flag2 = false;
                            }if(!reg.test(stock)){
                                $(".error4").html("商品库存只能为整数");
                                flag2 = false;
                            }else {
                                $(".error4").html("");
                                flag2 = true;
                            }
                        });

                        var reg_img=/.+\.(jpg|jpeg|gif|bmp|png)$/;
                        $(".file").change(function () {
                            var file = $(".file").val();
                            if(!reg_img.test(file)){
                                $(".error5").html("图片只能为jpg,jpeg,gif,bmp,png格式");
                                flag3 = false;
                            }else {
                                $(".error5").html("");
                                flag3 = true;
                            }
                        })

                        $(".xgspxx").click(function () {
                            var name = $(".name").val();
                            var price = $(".price").val();
                            var stock = $(".stock").val();
                            if(!flag || !flag1 || !flag2 || !flag3){

                            }else if(name==""){
                                $(".error1").html("商品名字不能为空");
                            }else if(price==""){
                                $(".error3").html("商品价格不能为空");
                            }else if(stock==""){
                                $(".error4").html("商品库存不能为空");
                            }else {
                                $.ajax({
                                    //将表单转化为二进制
                                    url : "news/updateSP",
                                    type : "POST",
                                    cache : false,
                                    data : new FormData($("#formXG")[0]),
                                    processData : false,
                                    contentType : false,
                                    dataType : "json",
                                    success : function (rss) {
                                        if(rss == true){
                                            alert("修改成功");
                                            $(".m_right").empty();
                                            productList(num);
                                        }else if(rss==false){
                                            alert("修改失败");
                                            $(".m_right").empty();
                                            productList(num);
                                        }
                                    }
                                })
                            }
                        })

                    })

                })
            })

        })



    }
    //点击商品管理+++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".spgl").click(function () {
        productList(1);
    })


    //分类管理++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    function feileiGL(pagenum){
        $(".m_right").empty();
        $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px;margin-bottom: 10px">分类列表</h1>\n' +
            '\t\t\t<div class="address">\n' +
            '            \t<table border="1" class="add_t"  style="width:98%; margin:10px auto; text-align: center;font-size: 16px" cellspacing="0" cellpadding="0">\n' +
            '                </table>\n' +
            '            </div>\n' +
            '\n' +
            '            <div id="yeshu" class="pages">\n' +
            '                <span style="border-color: #333333;border : 1px solid #000000;border-width: 2px;display:inline-block;width: 40px;height:50px;text-align: center;margin-top: 50px;margin-left: 30px">\n' +
            '                    <a href="" style="font-size: 25px;margin-top: 10px;display: inline-block">1</a>\n' +
            '                </span>\n' +
            '            </div>' +
            '            <div><a  style="font-size: 30px;margin-left: 50px;margin-top: 50px;margin-bottom: 10px;background-color: #91b817" class="tjfl">添加分类</a></div>' +
            '<div class="yincang" style="margin-top: 100px;margin-left: 200px"></div>'))

        $(".add_t").empty();
        $("#yeshu").empty();
        $(".add_t").append($('<tr style="font-size: 16px">\n' +
            '                    <th>名称</th>\n' +
            '                    <th>所属级别</th>\n' +
            '                    <th>有无父级</th>\n' +
            '                   <th>操作</th>\n' +
            '                </tr>'));

        $.post("news/categoryAll",{"pagenum":pagenum},function (data) {
            $.each(data.list,function (index,category) {
                var type = "一级分类";
                if(category.type==2){
                    type = "二级分类";
                }else if(category.type==3) {
                    type = "三级分类";
                }
                var parentId = "有";
                if(category.parentid==0){
                    parentId = "无";
                }
                $(".add_t").append($('<tr style="font-size: 16px">\n' +
                    '                    <th>'+category.name+'</th>\n' +
                    '                    <th>'+type+'</th>\n' +
                    '                    <th>'+parentId+'</th>\n' +
                    '                 <th><a href="javascript:;" class="xiugai" data-id="'+category.id+'" data-num="'+pagenum+'">修改</a> &nbsp; &nbsp;<a href="javascript:;" class="shanchu" data-id="'+category.id+'" data-num="'+pagenum+'">删除</a></th>\n' +
                    '                </tr>'));
            });

            if(data.hasPreviousPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="1">首页</a>\n' +
                    '                </span>')
            }
            $.each(data.navigatepageNums,function (i,a) {
                if(a==data.pageNum){
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" style="background-color: pink" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }else {
                    $("#yeshu").append('<span>\n' +
                        '                    <a href="javascript:void(0)" class="yeshu" data-id="'+a+'">'+a+'</a>\n' +
                        '                </span>')
                }
            });
            if(data.hasNextPage){
                $("#yeshu").append('<span>\n' +
                    '                    <a href="javascript:void(0)" class="yeshu" data-id="'+data.pages+'">末页</a>\n' +
                    '                </span>')
            }

            $(".yeshu").click(function () {
                var a = $(this).data("id");
                feileiGL(a)
            })

            //点击删除+++++++++++++++++++++++++++++++++++++++++++
            $(".shanchu").click(function () {
                if(confirm("是否删除此分类")){
                    var id = $(this).data("id");
                    var num = $(this).data("num");
                    $.post("news/deleteFenLei",{"id":id},function (rs) {
                        if(rs=="true"){
                            alert("删除成功")
                            feileiGL(num);
                        }else{
                            alert("该分类下还有子分类或者商品")
                            feileiGL(num);
                        }
                    })
                }
            })

            //添加分类+++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".tjfl").click(function () {
                $(".yincang").empty();
                $(".yincang").append($('<div style="font-size: 20px;margin-top: 50px;margin-left: 150px">\n' +
                    '\n' +
                    '                <div class="cuanze" style="margin-top: 40px">\n' +
                    '      选择分类：<select class="xzfl">\n' +
                    '              <option value="1" selected>一级分类</option>\n'+
                    '              <option value="2">二级分类</option>\n'+
                    '              <option value="3">三级分类</option>\n'+
                    '                </select>\n' +
                    '                </div>\n' +
                    '\n' +
                    '                <div class="fenlei1" style="margin-top: 40px">\n' +
                    '                    所属一级分类：<select class="CLL1">\n' +
                    '                </select>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '                <div class="fenlei2" style="margin-top: 40px">\n' +
                    '                    所属二级分类：<select class="CLL2">\n' +
                    '                </select>\n' +
                    '                </div>\n' +
                    '            </div>'+
                    '                <div style="margin-top: 40px;font-size:20px ">\n' +
                    '                    分类名称：<input type="flname" name="flname" class="flname" style="width: 400px;height: 40px;font-size: 20px">\n' +
                    '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
                    '                </div>\n' +
                    '<div style="margin-left: 600px;margin-top: 50px"><input type="button" value="添加分类" class="tianjiafenlei" style="font-size: 20px;background-color: #91b817"></div>\n'))
                $(".fenlei1").hide();
                $(".fenlei2").hide();

                $.post("news/spfenlei",{"type":1},function (rs) {
                    $(".xzfl").change(function () {
                        var type = $(".xzfl").val();
                        if(type==1){
                            $(".fenlei1").hide();
                            $(".fenlei2").hide();
                        }else if(type==2){
                            $(".fenlei1").show();
                            $(".fenlei2").hide();
                            $(".CLL1").empty();
                            $(".CLL1").append($('<option value="0" class="cl1">请选择</option>'));
                            $.each(rs[0],function (index,order) {
                                    $(".CLL1").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
                            });
                        }else if(type==3){
                            $(".fenlei1").show();
                            $(".fenlei2").show();
                            $(".CLL1").empty();
                            $(".CLL2").empty();

                            $(".CLL1").append($('<option value="0" class="cl1" selected>请选择</option>'));
                            $(".CLL2").append($('<option value="0" class="cl2" selected>请选择</option>'));
                            $.each(rs[0],function (index,order) {
                                $(".CLL1").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
                            })
                        }
                    })
                    $(".CLL1").change(function () {
                        var a = $(this).val();
                        if(a==0){
                            $(".CLL2").empty();
                            $(".CLL2").append($('<option value="0" class="cl2" selected>请选择</option>'));
                        }else {
                            $(".CLL2").empty();
                            $(".CLL2").append($('<option value="0" class="cl2" selected>请选择</option>'));
                            $.each(rs[1],function (index,order) {
                                if(order.parentid==a){
                                    $(".CLL2").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                                }
                            });
                        }
                    })
                });

                //验证++++++++++++++++++++++++++++++++++++++++++++++++
                $(".tianjiafenlei").click(function () {
                    var name = $(".flname").val();
                    var type = $(".xzfl").val();
                    var C1 = $(".CLL1").val();
                    var C2 = $(".CLL2").val();
                    var flag = true;
                    $.post("news/selectName",{"name":name},function (rss) {
                        if(rss=="false"){
                            $(".error1").html("分类名字重复");
                            flag = false;
                        }else if(name==""){
                            $(".error1").html("分类名字不能为空");
                            flag = false;
                        }else {
                            $(".error1").html("");
                            flag = true;
                        }
                    })

                    if(type==2 && C1==0){
                        alert("其选择其所属一级分类")
                    }else if(type==3 && (C1==0 || C2==0)){
                        alert("其选择其所属一级或二级分类")
                    }else if(flag==false){
                        alert("分类名字重复")
                    }else {
                        var parentid;
                        if(type==1){
                            parentid=0;
                        }else if(type==2){
                            parentid=C1;
                        }else if(type==3){
                            parentid=C2;
                        }
                        $.post("news/insertC",{"name":name,"type":type,"parentid":parentid},function (rss) {
                            if(rss=="true"){
                                alert("添加成功");
                                feileiGL(1);
                            }else if(rss=="false"){
                                alert("添加失败");
                            }
                        })
                    }
                })

            })

            //修改分类+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".xiugai").click(function () {
                var num = $(this).data("num");
                var id = $(this).data("id");
                var yuanname;
                
                $(".yincang").empty();
                $(".yincang").append($('<div style="font-size: 20px;margin-top: 50px;margin-left: 150px">\n' +
                    '\n' +
                    '                <div class="cuanze" style="margin-top: 40px">\n' +
                    '      选择分类：<select class="xzfl" disabled>\n' +
                    '              <option value="1">一级分类</option>\n'+
                    '              <option value="2">二级分类</option>\n'+
                    '              <option value="3">三级分类</option>\n'+
                    '                </select>\n' +
                    '                </div>\n' +
                    '\n' +
                    '                <div class="fenlei1" style="margin-top: 40px">\n' +
                    '                    所属一级分类：<select class="CLL1">\n' +
                    '                </select>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '                <div class="fenlei2" style="margin-top: 40px">\n' +
                    '                    所属二级分类：<select class="CLL2">\n' +
                    '                </select>\n' +
                    '                </div>\n' +
                    '            </div>'+
                    '                <div style="margin-top: 40px;font-size:20px ">\n' +
                    '                    分类名称：<input type="flname" name="flname" class="flname" style="width: 400px;height: 40px;font-size: 20px">\n' +
                    '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
                    '                </div>\n' +
                    '<div style="margin-left: 600px;margin-top: 50px"><input type="button" value="修改分类" class="xiugaifenlei" style="font-size: 20px;background-color: #91b817"></div>\n'))

                $(".CLL2").empty();
                $(".CLL1").empty();
                $.post("news/spfenlei",{"type":1},function (list) {
                    $.post("news/Cbyid",{"id":id},function (rs) {
                        yuanname=rs.name;
                        $(".flname").val(rs.name);
                        $(".xzfl").val(rs.type);
                        if(rs.type==1){
                            $(".fenlei1").hide();
                            $(".fenlei2").hide();
                        }else if(rs.type==2){
                            $(".fenlei2").hide();
                            $(".fenlei1").show();
                            $(".CLL1").empty();
                            $(".CLL1").append($('<option value="0" class="cl1">请选择</option>'));
                            $.each(list[0],function (index,order) {
                                if(order.id==rs.parentid){
                                    $(".CLL1").append($('<option value="'+order.id+'" class="cl1" selected>'+order.name+'</option>'))
                                }else{
                                    $(".CLL1").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
                                }
                            });
                        }else if(rs.type==3){
                            $(".fenlei1").show();
                            $(".fenlei2").show();
                            $(".CLL1").empty();
                            $(".CLL2").empty();
                            var ppid;
                            $(".CLL2").append($('<option value="0" class="cl2">请选择</option>'));
                            $.each(list[1],function (index,order) {
                                if(order.id==rs.parentid){
                                    ppid=order.parentid;
                                }
                            });
                            $.each(list[1],function (index,order) {
                                if(order.id==rs.parentid){
                                    ppid=order.parentid;
                                    $(".CLL2").append($('<option value="'+order.id+'" class="cl2" selected>'+order.name+'</option>'))
                                }else if(ppid==order.parentid){
                                    $(".CLL2").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                                }
                            });

                            $(".CLL1").append($('<option value="0" class="cl1">请选择</option>'));
                            $.each(list[0],function (index,order) {
                                if(order.id==ppid){
                                    $(".CLL1").append($('<option value="'+order.id+'" class="cl1" selected>'+order.name+'</option>'))
                                }else {
                                    $(".CLL1").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
                                }
                            });
                            $(".m_right").on("change",".CLL1",function () {
                                var a = $(this).val();
                                if(a==0){
                                    $(".CLL2").empty();
                                    $(".CLL2").append($('<option value="0" class="cl2" selected>请选择</option>'));
                                }else {
                                    $(".CLL2").empty();
                                    $(".CLL2").append($('<option value="0" class="cl2" selected>请选择</option>'));
                                    $.each(list[1],function (index,order) {
                                        if(order.parentid==a){
                                            $(".CLL2").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                                        }
                                    });
                                }
                            })
                        }
                    })

                });
                //验证修改+++++++++++++++++++++++++++++++++++++++++++++++++++++++
                $(".xiugaifenlei").click(function () {
                    var name = $(".flname").val();
                    var type = $(".xzfl").val();
                    var C1 = $(".CLL1").val();
                    var C2 = $(".CLL2").val();
                    var flag = false;
                    $.post("news/selectName",{"name":name},function (rss) {
                        if(rss=="false" && yuanname!=name){
                            $(".error1").html("分类名字重复");
                            flag = false;
                        }else if(name==""){
                            $(".error1").html("分类名字不能为空");
                            flag = false;
                        }else {
                            $(".error1").html("");
                            flag = true;
                        }
                    })
                    if(type==2 && C1==0){
                        alert("其选择其所属一级分类")
                    }else if(type==3 && (C1==0 || C2==0)){
                        alert("其选择其所属一级或二级分类")
                    }else if(flag){
                    }else {
                        var parentid;
                        if(type==1){
                            parentid=0;
                        }else if(type==2){
                            parentid=C1;
                        }else if(type==3){
                            parentid=C2;
                        }
                        $.post("news/updateC",{"name":name,"type":type,"parentid":parentid,"id":id},function (rss) {
                            if(rss=="true"){
                                alert("修改成功");
                                feileiGL(num);
                            }else if(rss=="false"){
                                alert("修改失败");
                            }
                        })
                    }
                })
            })
            
            
        })

    }

    //点击分类管理+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $(".flgl").click(function () {
        feileiGL(1);
    })


    //我的收藏++++++++++++++++++++++++++++++++++++++++++++++++
    function showSC() {
        $(".m_right").empty();
        $(".m_right").append($('<h1 style="font-size: 30px;margin-left: 50px;margin-top: 50px"><span>我的收藏</span></h1>' +
            '            <table border="1px" width="90%" style="font-size: 16px;margin-top: 30px" id="xianshi" cellspacing="0px">\n' +
            '            </table>\n'));

        $("#xianshi").empty();
        $("#xianshi").append($('<tr style="font-size: 16px">\n' +
            '                    <th>商品示例</th>\n' +
            '                    <th>商品名字</th>\n' +
            '                    <th>商品价格</th>\n' +
            '                 <th>操作</th>\n' +
            '                </tr>'));

        $.post("news/showshoucang",{},function (list) {
            console.log(list)
            $.each(list, function (index, produck) {
                $("#xianshi").append($('<tr style="font-size: 16px">\n' +
                    '                    <th><img src="../../files/' + produck.filename + '" style="width: 50px;height: 50px"></th>\n' +
                    '                    <th>' + produck.name + '</th>\n' +
                    '                    <th>' + produck.price + '￥</th>\n' +
                    '                 <th> &nbsp; &nbsp;<a href="javascript:;" class="shanchuSC" data-id="' + produck.id + '">删除</a></th>\n' +
                    '                </tr>'));
            })

            //删除收藏+++++++++++++++++++++++++++++++++++++++++++++++++++
            $(".shanchuSC").click(function () {
                if(confirm("是否确认删除此收藏商品")){
                    var id = $(this).data("id");
                    $.post("news/deleteSC",{"id":id},function (rs) {
                        if(rs=="false"){
                            alert("删除收藏失败");
                            showSC();
                        }else if(rs=="true"){
                            alert("删除收藏成功");
                            showSC();
                        }
                    })
                }
            })
        });

       /* //删除收藏+++++++++++++++++++++++++++++++++++++++++++++++++++
        $(".m_right").on("click",".shanchu",function () {
            if(confirm("是否确认删除此收藏商品")){
                var id = $(this).data("id");
                $.post("news/deleteSC",{"id":id},function (rs) {
                    if(rs=="false"){
                        alert("删除收藏失败");
                        showSC();
                    }else if(rs=="true"){
                        alert("删除收藏成功");
                        showSC();
                    }
                })
            }
        })*/

    }

    //点击我的收藏
    $(".wdsc").click(function () {
        showSC();
    })


    //添加商品++++++++++++++++++++++++++++++++++++++++++++++++
    function addSP() {
        $(".m_right").empty();
        $(".m_right").append($('<form id="formXG" action=""><h1 style="font-size: 30px;margin-left: 400px;margin-top: 50px">增加商品</h1>\n' +
            '            <div style="font-size: 20px;margin-top: 50px;margin-left: 150px">\n' +
            '                <div>\n' +
            '                    名字：<input type="text" name="name" class="name" value="" style="width: 400px;height: 40px;font-size: 20px">\n' +
            '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error1"></div>\n' +
            '                </div>\n' +
            '\n' +
            '                <div style="margin-top: 40px">\n' +
            '                    描述：<input type="text" name="description" value="" class="description" style="width: 400px;height: 40px;font-size: 20px">\n' +
            '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error2"></div>\n' +
            '                </div>\n' +
            '\n' +
            '                <div style="margin-top: 40px">\n' +
            '                    价格：<input type="text" name="price" value="" class="price" style="width: 400px;height: 40px;font-size: 20px">\n' +
            '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error3"></div>\n' +
            '                </div>\n' +
            '\n' +
            '                <div style="margin-top: 40px">\n' +
            '                    库存：<input type="text" name="stock" value="" class="stock" style="width: 400px;height: 40px;font-size: 20px">\n' +
            '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error4"></div>\n' +
            '                </div>\n' +
            '\n' +
            '                <div class="fenlei1" style="margin-top: 40px">\n' +
            '                    一级分类：<select class="categorylevel1id" name="categorylevel1id">\n'+
            '              <option value="0" class="cl1">请选择</option>'+
            '                </select>\n' +
            '                </div>\n' +
            '\n' +
            '                <div class="fenlei2" style="margin-top: 40px">\n' +
            '                    二级分类：<select class="categorylevel2id" name="categorylevel2id">\n' +
            '              <option value="0" class="cl2">请选择</option>'+
            '                </select>\n' +
            '                </div>\n' +
            '\n' +
            '                <div class="fenlei3" style="margin-top: 40px">\n' +
            '                    三级分类：<select class="categorylevel3id" name="categorylevel3id">\n' +
            '              <option value="0" class="cl3">请选择</option>'+
            '                </select>\n' +
            '                </div>\n' +
            '\n' +
            '                <div style="margin-top: 40px">\n' +
            '                    图片：<img src="" alt=""><input type="file" name="file" class="file">\n' +
            '                    <div style="font-size: 16px;color: red;margin-left: 60px" class="error5"></div>\n' +
            '                </div>\n' +
            '                \n' +
            '         </div>\n' +
            '                <div style="margin-left: 650px;margin-top: 50px"><input type="button" value="增加商品" class="zjsp" style="font-size: 16px;background-color: #91b817"></div>' +
            '</form>'));

        $.post("news/spfenlei",{"type":1},function (list) {
            $(".categorylevel1id").empty();
            $(".categorylevel2id").empty();
            $(".categorylevel3id").empty();

            $(".fenlei2").hide();
            $(".fenlei3").hide();
            $(".categorylevel1id").append($('<option value="0" class="cl1">请选择</option>'))
            $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'));
            $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
            $.each(list[0],function (index,order) {
                    $(".categorylevel1id").append($('<option value="'+order.id+'" class="cl1">'+order.name+'</option>'))
            });

            $(".categorylevel1id").change(function () {
                var a = $(this).val();
                if(a==0){
                    $(".fenlei2").hide();
                    $(".categorylevel2id").empty();
                    $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'));
                    $(".categorylevel3id").empty();
                    $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                }else {
                    $(".fenlei2").show();
                    $(".categorylevel3id").empty();
                    $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                }
                $(".categorylevel2id").empty();
                $(".fenlei3").hide();
                $(".categorylevel2id").append($('<option value="0" class="cl2">请选择</option>'));
                $.each(list[1],function (index,order) {
                    if(order.parentid==a){
                        $(".categorylevel2id").append($('<option value="'+order.id+'" class="cl2">'+order.name+'</option>'))
                    }
                });
            });

            $(".categorylevel2id").change(function () {
                var a = $(this).val();
                if(a==0){
                    $(".fenlei3").hide();
                    $(".categorylevel3id").empty();
                    $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                }else {
                    $(".fenlei3").show();
                }
                $(".categorylevel3id").empty();
                $(".categorylevel3id").append($('<option value="0" class="cl3">请选择</option>'));
                $.each(list[2],function (index,order) {
                    if(order.parentid==a){
                        $(".categorylevel3id").append($('<option value="'+order.id+'" class="cl3">'+order.name+'</option>'))
                    }
                });
            })


            var flag = true;
            var flag1 = true;
            var flag2 = true;
            var flag3 = true;
            $(".name").blur(function () {
                var name = $(".name").val();
                if(name==""){
                    $(".error1").html("商品名字不能为空");
                    flag=false;
                }else {
                    $.post("news/produckByName",{"name":name},function (rs) {
                        if(rs=="false"){
                            $(".error1").html("商品名字可以使用");
                            flag = true;
                        }else if(rs=="true"){
                            $(".error1").html("商品名字重复");
                            flag = false;
                        }
                    })
                }
            })

            var reg = /^[0-9]*[1-9][0-9]*$/;
            var reg1 = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/;

            $(".price").blur(function () {
                var price = $(".price").val();
                if(price==""){
                    $(".error3").html("商品价格不能为空");
                    flag1 = false;
                }if(!reg1.test(price)){
                    $(".error3").html("商品价格只能为数字，包括带小数点的数字");
                    flag1 = false;
                }else {
                    $(".error3").html("");
                    flag1 = true;
                }
            });

            $(".stock").blur(function () {
                var stock = $(".stock").val();
                if(stock==""){
                    $(".error4").html("商品库存不能为空");
                    flag2 = false;
                }if(!reg.test(stock)){
                    $(".error4").html("商品库存只能为整数");
                    flag2 = false;
                }else {
                    $(".error4").html("");
                    flag2 = true;
                }
            });

            var reg_img=/.+\.(jpg|jpeg|gif|bmp|png)$/;
            $(".file").change(function () {
                var file = $(".file").val();
                if(file==""){
                    $(".error5").html("图片不能为空");
                    flag3 = false;
                }else if(!reg_img.test(file)){
                    $(".error5").html("图片只能为jpg,jpeg,gif,bmp,png格式");
                    flag3 = false;
                }else {
                    $(".error5").html("");
                    flag3 = true;
                }
            })

            $(".zjsp").click(function () {
                alert(1234)
                var name = $(".name").val();
                var price = $(".price").val();
                var stock = $(".stock").val();
                var filename = $(".file").val();
                if(!flag || !flag1 || !flag2 || !flag3){

                }else if(name==""){
                    $(".error1").html("商品名字不能为空");
                }else if(price==""){
                    $(".error3").html("商品价格不能为空");
                }else if(stock==""){
                    $(".error4").html("商品库存不能为空");
                }else if(filename==""){
                    $(".error5").html("图片不能为空");
                }else {
                    alert(456);
                    $.ajax({
                        //将表单转化为二进制
                        url : "news/addSP",
                        type : "POST",
                        cache : false,
                        data : new FormData($("#formXG")[0]),
                        processData : false,
                        contentType : false,
                        dataType : "json",
                        success : function (rss) {
                            if(rss == true){
                                alert("增加商品成功");
                                productList(1);
                            }else if(rss==false){
                                alert("增加商品失败");
                                productList(1);
                            }
                        }
                    })
                }
            })
        })


    }

    $(".spsj").click(function () {
        addSP();
    })

})